package com.phone.html5.email;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.phone.html5.Html5Action;
import com.xt.base.wireless.server.MobileActionUtil;

public class EmailAction extends Html5Action{

	private static final long serialVersionUID = 8151511874055280098L;
	
	@SuppressWarnings("unchecked")
	public String emailList(){
		this.putBaseParam();
		paramMap.put("code", 1);
		paramMap.put("defaultpagesize", defaultpagesize);
		paramMap.put("pagenumber", pageNumber);
		paramMap.put("funcid", "D001");
		//xmlString = this.approveService.queryApproveList(paramMap);
		resultMap = MobileActionUtil.parseRequestXml(xmlString);
		this.dealPageNumber((List<Object>)resultMap.get("list"));
		resultString = "emailList.jsp";
		return "resultString";
	}
	public String getContent(){
		this.putBaseParam();
		paramMap.put("code", 2);
		paramMap.put("funcid", "D001");
		/*paramMap.put("universalid", universalid);
		xmlString = this.approveService.getApproveInfo(paramMap);
		*/resultMap = MobileActionUtil.parseRequestXml(xmlString);
		resultString = "emailContent.jsp";
		return "resultString";
	}
	@SuppressWarnings("unchecked")
	public String queryEmail(){
		this.putBaseParam();
		paramMap.put("code", 1);
		paramMap.put("defaultpagesize", defaultpagesize);
		paramMap.put("pagenumber", pageNumber);
		paramMap.put("funcid", "D005");
		if("session".equals(scope)){
			paramMap.put("fromuser", this.getSessionAttr("fromuser"));
			paramMap.put("worktype", this.getSessionAttr("worktype"));
			paramMap.put("keyword", this.getSessionAttr("keyword"));
		}else{
			String s = this.getParam("fromuser");
			this.setSessionAttr("fromuser", s);
			paramMap.put("fromuser", s);
			
			s = this.getParam("worktype");
			this.setSessionAttr("worktype", s);
			paramMap.put("worktype", s);
			
			s = this.getParam("keyword");
			this.setSessionAttr("keyword", s);
			paramMap.put("keyword", s);
		}
		//xmlString = this.approveService.queryApproveList(paramMap);
		resultMap = MobileActionUtil.parseRequestXml(xmlString);
		this.dealPageNumber((List<Object>)resultMap.get("list"));
		resultString = "emailList.jsp";
		return "resultString";
	}
	public String sendEmail(){
		List<String> list = new ArrayList<String>();
		String s = this.getParam("sendto");
		if(s!=null && !s.equals("")){
			list = Arrays.asList(s.split(","));
		}else{
			list.add("");
		}
		this.putBaseParam();
		paramMap.put("code", 1);
		paramMap.put("funcid", "D002");
		paramMap.put("randomid",new Random().nextLong());
		paramMap.put("sendto",list);
		paramMap.put("toshow",this.getParam("toshow"));
		paramMap.put("title",this.getParam("title"));
		paramMap.put("content",this.getParam("content"));
		paramMap.put("date",new Date().getTime());
		//xmlString = this.approveService.saveOrUpdate(paramMap);
		resultMap = MobileActionUtil.parseRequestXml(xmlString);
		resultString = "emailSend.jsp";
		return "resultString";
	}
}
